 *************************************************************
 *************************************************************
 *** STAGGERED SPECIFICATION GRAPHS: FIGURE 4 / FIGURE 5 / FIGURE A3 / FIGURE A4
 *************************************************************
 *************************************************************
use "${path}data_table.dta", clear

label var nb_collab_same_labex "\emph{Links}" 
label var nbpub_same_labex "\emph{CollaPubs}"
label var npubs_outside "\emph{ExternalPubs}"
label var nb_collab_same_labex "\emph{Links}"
label var nb_first_same_labex    "\emph{NewLinks}"
label var nb_collabpub_same_labex "\emph{Collaborations}"
label var npubs "\emph{Pubs}"
label var citations_new "\emph{Cites}"
label var npubs_weight   "\emph{PubsAdj}"
label var tcs "\emph{Cites}"
label var np_if_3y "\emph{AIF}"
label var top95_ay   "\emph{Top5}"
label var top90_ay   "\emph{Top10}"
local varlist "npubs citations_new np_if_3y top90_ay  top95_ay nb_first_same_labex nbpub_same_labex  npubs_outside nb_collab_same_labex nb_collabpub_same_labex    " 
foreach var of local varlist{
preserve
gen discipline=0
replace discipline=1 if biologie_fondamentale ==1
replace discipline=2 if recherche_medicale ==1
replace discipline=3 if biologie_appliquee_ecologie ==1
replace discipline=4 if chimie ==1
replace discipline=5 if physique ==1
replace discipline=6 if sciences_univers ==1
replace discipline=7 if sciences_ingenieur ==1
replace discipline=8 if mathematiques ==1
replace discipline=9 if SS ==1
replace discipline=10 if SH ==1
gen age_2010 = age if year ==2010
bys id_20:  egen age_in_2010=max( age_2010)
drop age_2010
gen treated = 0
replace treated = year_labex +1  if year_labex !=. & accepted ==1
egen idlabex=group(labexid)
egen ididlabex=group(labexid id_2019)
keep if criterion_grade==1
csdid `var'  i.discipline#i.year age_in_2010#i.year female_new#i.year  year, method(reg) time(year) ivar(ididlabex) gvar(treated) cluster(idlabex) agg(event) saverif(even_`var')  replace 
qui :  estadd ysumm  
qui :  estadd scalar clusters = e(N_clust)
estat group, estore(reg_`var') replace
estat group, estsave(reg_`var')  replace
restore
preserve
use even_`var', clear
qui csdid_stats event
csdid_plot, style(rcap)
graph export "staggered_`var'.pdf", as(pdf) replace
restore
} 
